package cn.xgc;

import cn.xgc.entity.News;

import java.util.ArrayList;
import java.util.List;

//创建一个新闻列表，并在列表中可以新增新闻
public class Test1 {
    public static void main(String[] args) {
        //使用数组创建新闻列表
        News[] newsArr = {
                new News("新闻1","随便编的内容1"), //0
                new News("新闻2","随便编的内容2"), //1
                new News("新闻3","随便编的内容3"), //2
        };

        //新增新闻
        //newsArr[3]=new News("新闻4","随便编的内容4");

        for (int i = 0; i < newsArr.length; i++) {
            System.out.println(newsArr[i]);
        }

        //创建一个新闻类型的列表
        List<News> newsList = new ArrayList<News>();
        newsList.add(new News("新闻1","随便编的内容1"));
        newsList.add(new News("新闻2","随便编的内容2"));
        newsList.add(new News("新闻3","随便编的内容3"));
        newsList.add(new News("新闻4","随便编的内容4"));

        //遍历列表
        for (int i = 0; i < newsList.size(); i++) {
            System.out.println(newsList.get(i));
        }


    }

}
